//1283. 使结果不超过阈值的最小除数
class Solution {
public:
    int smallestDivisor(vector<int>& nums, int threshold) {
        auto check= [&](int m) -> bool{
            int sum=0;
            for(int x:nums){
                sum +=(x+m-1)/m;
                if(sum>threshold){//提前退出循环
                    return false;
                }
            }
            return true;
        };

        int left=1,right=ranges::max(nums);
        while(left<=right){
            int mid =left+(right-left)/2;
            if(check(mid))
                right=mid-1;
            else
                left=mid+1;
        }
        return left;
    }
};

